//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include <ddk.h>
#include <bulverde.h>

EXTERN_C void D_Delay(unsigned int uSec)
{
    DzDelay(uSec);
}

#define V_OSCR (*(volatile unsigned long*)((unsigned int)v_PerifBase + 0x00A00010))
EXTERN_C void OSTDelay(int uSec)
{
	unsigned long delaytime = (unsigned long)(uSec * 3);	// approx 3 ticks per uS
    unsigned long time = V_OSCR;
    unsigned long expireTime = delaytime + time;
    //
    // Check if we wrapped on the expireTime
    // and OSTDelay first part until wrap
    //
	if (expireTime < time) {
		while (time < V_OSCR);
	}
	while (V_OSCR <= expireTime);
    return;
}


